/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "display_layer.h"
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <securec.h>
#include "display_type.h"
#include "hdf_log.h"
#include "hdf_io_service_if.h"
#include "hdf_sbuf.h"

#define DEV_ID                   0
#define LAYER_ID                 0

static int32_t InitDisplay(uint32_t devId)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t DeinitDisplay(uint32_t devId)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetDisplayInfo(uint32_t devId, DisplayInfo *dispInfo)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t CreateLayer(uint32_t devId, const LayerInfo *layerInfo, uint32_t *layerId)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t CloseLayer(uint32_t devId, uint32_t layerId)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerVisible(uint32_t devId, uint32_t layerId, bool visible)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerVisibleState(uint32_t devId, uint32_t layerId, bool *visible)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerSize(uint32_t devId, uint32_t layerId, IRect *rect)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerSize(uint32_t devId, uint32_t layerId, IRect *rect)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerCrop(uint32_t devId, uint32_t layerId, IRect *rect)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t zorder)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerZorder(uint32_t devId, uint32_t layerId, uint32_t *zorder)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerPreMulti(uint32_t devId, uint32_t layerId, bool preMul)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerPreMulti(uint32_t devId, uint32_t layerId, bool *preMul)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerAlpha(uint32_t devId, uint32_t layerId, LayerAlpha *alpha)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerAlpha(uint32_t devId, uint32_t layerId, LayerAlpha *alpha)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerColorKey(uint32_t devId, uint32_t layerId, bool enable, uint32_t key)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerColorKey(uint32_t devId, uint32_t layerId, bool *enable, uint32_t *key)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerPalette(uint32_t devId, uint32_t layerId, uint32_t *palette, uint32_t len)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerPalette(uint32_t devId, uint32_t layerId, uint32_t *palette, uint32_t len)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetTransformMode(uint32_t devId, uint32_t layerId, TransformType type)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerCompression(uint32_t devId, uint32_t layerId, int32_t compType)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerCompression(uint32_t devId, uint32_t layerId, int32_t *compType)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerDirtyRegion(uint32_t devId, uint32_t layerId, IRect *region)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerBuffer(uint32_t devId, uint32_t layerId, LayerBuffer *buffer)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t Flush(uint32_t devId, uint32_t layerId, LayerBuffer *buffer)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t WaitForVBlank(uint32_t devId, uint32_t layerId, int32_t timeOut)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SnapShot(uint32_t devId, LayerBuffer *buffer)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerVisibleRegion(uint32_t devId, uint32_t layerId, uint32_t num, IRect *rect)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerBuffer(uint32_t devId, uint32_t layerId, const BufferHandle *buffer, int32_t fence)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t InvokeLayerCmd(uint32_t devId, uint32_t layerId, uint32_t cmd, ...)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerCompositionType(uint32_t devId, uint32_t layerId, CompositionType type)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerBlendType(uint32_t devId, uint32_t layerId, BlendType type)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerColorTransform(uint32_t devId, uint32_t layerId, const float *matrix)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerColorDataSpace(uint32_t devId, uint32_t layerId, ColorDataSpace colorSpace)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t GetLayerColorDataSpace(uint32_t devId, uint32_t layerId, ColorDataSpace *colorSpace)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerMetaData(uint32_t devId, uint32_t layerId, uint32_t num, const HDRMetaData *metaData)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}

static int32_t SetLayerMetaDataSet(uint32_t devId, uint32_t layerId, HDRMetadataKey key, uint32_t num,
                                   const uint8_t *metaData)
{
    HDF_LOGI("%s", __func__);
    return DISPLAY_SUCCESS;
}


int32_t LayerInitialize(LayerFuncs **funcs)
{
    static LayerFuncs *lFuncs = NULL;

    if (funcs == NULL) {
        HDF_LOGE("%s: funcs is null", __func__);
        return DISPLAY_NULL_PTR;
    }

    if (lFuncs == NULL) {
        lFuncs = (LayerFuncs *)OsalMemCalloc(sizeof(LayerFuncs));
        if (lFuncs == NULL) {
            HDF_LOGE("%s: lFuncs is null", __func__);
            return DISPLAY_NULL_PTR;
        }

        lFuncs->InitDisplay = InitDisplay;
        lFuncs->DeinitDisplay = DeinitDisplay;
        lFuncs->GetDisplayInfo = GetDisplayInfo;
        lFuncs->CreateLayer = CreateLayer;
        lFuncs->CloseLayer = CloseLayer;
        lFuncs->Flush = Flush;
        lFuncs->GetLayerBuffer = GetLayerBuffer;
    }
    *funcs = lFuncs;

    HDF_LOGI("%s: success", __func__);
    return DISPLAY_SUCCESS;
}

int32_t LayerUninitialize(LayerFuncs *funcs)
{
    if (funcs == NULL) {
        HDF_LOGE("%s: funcs is null", __func__);
        return DISPLAY_NULL_PTR;
    }

    HDF_LOGI("%s: layer uninitialize success", __func__);
    return DISPLAY_SUCCESS;
}

